<?
/**
* <b>jsonRenderer</b>
*
* Renderer for JsOn
*
* @package gravy.classes.renderers
* @class jsonRenderer extends renderer
* @author Lars Sorhus (lars@saucecode.com.au)
*/
class jsonRenderer extends renderer{	
	/**
         * <b>__construct</b>
         *
         * Calls base constructor
         *
         * @fn __construct
         * @param $gravy
         * @return void
         */
	public function __construct($gravy){
		// call the construct
		parent::__construct($gravy);
	}
	
	/**
	* <b>setHeadersForOutput</b>
	* Implementation of abstract function
	* Sets up the header information for HTML
	*
	* @fn setHeadersForOutput
	* @param $statusCode [def = null]
	* @return void
	*/
	public function setHeadersForOutput($statusCode=null){
		if(!$this->headerSent){			
			header("Content-Type: text/plain; charset=utf-8");		
			if($statusCode!=null){
				header(' ',true,$statusCode);
			}
			$this->headerSent=true;
			if($this->gravy->data["raw"]===TRUE){
				print($this->gravy->data["data"]);
				exit();
			}
		}
	}
	
	/**
	* <b>render</b>
	*
	* Sets output headers (base), gets bunch of stuff (validator, errors, templateData, doc var's, gravy
	* Includes helpers
	* if no fatal errors, include the theme file for display in the browser
	*
	* @fn render
	* @return void
	*/
	public function render(){
		// start the render process
		$ar=$this->gravy->getJsonData();
		$json_data=json_encode($ar);
		
		if(array_key_exists("jsoncallback",$_REQUEST)){
			print($_REQUEST["jsoncallback"]);
		}
		
		print($json_data);
	}
	
	/**
         * <b>renderError</b>
         *
         * todo
         *
         * @fn renderError
         * @param $statusCode
         * @return void
         */
	public function renderError($statusCode){
	}
};
?>
